package cn.wxxyhw.server;

import cn.wxxyhw.Dao.ArticleDao;
import cn.wxxyhw.Dao.UserDao;
import cn.wxxyhw.Entity.Article;
import cn.wxxyhw.Util.DateFormateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 说说
 * @Author: 洪稳
 * @Date: 2019/6/6
 */
@Service
public class ArticleServer {
    @Autowired
    private UserDao userDao;
    @Autowired
    private ArticleDao articleDao;
    /**
     * 查询所有说说
     * @return
     */
    public List<Article> getAll(){
        List<Article> list = articleDao.getAll();
        return list;
    }

    /**
     * 保存说说
     * @param desc
     * @param name
     * @param time
     */
    public void saveLiuYan(String desc, String name, String time,String id) {
        Article article = new Article();
        if (time!=null)
            desc+="<div><img class='h-img' src='/image/"+time+"'/></div>";
        article.setContent(desc);
        article.setDate(DateFormateUtil.getDateFormat().format(new Date()));
        article.setUname(userDao.getUserNameById(name));
        article.setUid(id);
        article.setDz(0);
        article.setLook(0);
        article.setImage(userDao.getImageByName(name));
        articleDao.save(article);
    }

    /**
     * 浏览记录加一
     */
    public void lookAddOne() {
        articleDao.lookAddOne();
    }

    /**
     * 点赞
     * @param id
     * @param option
     */
    public void dz(String id, String option) {
        int ID = Integer.parseInt(id);
        articleDao.dz(id,option);
    }

    /**
     * 删除说说
     * @param id
     */
    public void del(int id) {
        articleDao.del(id);
    }
}
